package gateway.rule.filter;

import gateway.api.annotation.Named;
import gateway.api.engine.Chain;
import gateway.api.engine.Filter;
import gateway.api.message.Context;
import gateway.api.message.HttpMessage;
import gateway.api.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @author Jin Zheng
 * @since 1.0 2020-09-11
 */
@Named("httpFilter")
public class HttpFilter implements Filter
{
	private static Logger logger = LoggerFactory.getLogger(HttpFilter.class);

	private Map<String, String> args;

	public HttpFilter()
	{
	}

	@Override
	public void handle(Message message, Chain chain)
	{
		Context context = message.context();
		if (message instanceof HttpMessage)
		{
			HttpMessage httpMessage = (HttpMessage) message;
			logger.info("url: {}", httpMessage.url());
		}
		chain.doNext();
	}

	@Override
	public void setArgs(Map<String, String> args)
	{
		this.args = args;
	}
}
